package com.jgame.secondarymarket.interfaces.assembler.product;

import cn.hutool.core.bean.BeanUtil;
import com.jgame.secondarymarket.domain.product.entity.ProductProperties;
import com.jgame.secondarymarket.domain.product.entity.Specification;
import com.jgame.secondarymarket.interfaces.dto.product.SpecificationDTO;
import com.jgame.secondarymarket.interfaces.query.product.UpdateSpecificationQuery;
import com.jgame.secondarymarket.interfaces.vo.product.ProductPropertiesVO;
import com.jgame.secondarymarket.interfaces.vo.product.SpecificationVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @title: SpecificationAssembler
 * @Author Wangsj
 * @Date: 2021/7/23
 */
public class SpecificationAssembler {

    public static List<Specification> toSpecificationList(List<SpecificationDTO> dtos) {
        return dtos.stream().map(dto -> {
            Specification specification = new Specification();
            BeanUtil.copyProperties(dto, specification);
            return specification;
        }).collect(Collectors.toList());
    }

    public static Specification toSpecification(SpecificationDTO dto) {
        Specification specification = new Specification();
        BeanUtil.copyProperties(dto, specification);
        return specification;

    }

    public static Specification toSpecification(UpdateSpecificationQuery query) {
        Specification specification = new Specification();
        BeanUtil.copyProperties(query, specification);
        return specification;

    }

    public static SpecificationVO toVO(Specification specification, List<ProductProperties> properties) {
        SpecificationVO specificationVO = new SpecificationVO();
        BeanUtil.copyProperties(specification, specificationVO);
        List<ProductPropertiesVO> productPropertiesVOS = properties.stream().map(x -> {
            ProductPropertiesVO productPropertiesVO = new ProductPropertiesVO();
            BeanUtil.copyProperties(x, productPropertiesVO);
            return productPropertiesVO;
        }).collect(Collectors.toList());
        specificationVO.setProperties(productPropertiesVOS);
        return specificationVO;

    }
}
